//
//  FLImageView.m
//  Cat
//
//  Created by lushitong on 2018/12/19.
//  Copyright © 2018年 lushitong. All rights reserved.
//

#import "FLImageView.h"
#import "UIImageView+RoundImage.h"

static NSString *headUrl = @"me_head_pic";


@implementation FLImageView

- (void)setDelegate:(id<FLImageViewDelegate>)delegate {
	_delegate = delegate;
}

- (instancetype)initWithFrame:(CGRect)frame {
	self = [super initWithFrame:frame];
	if (self) {
		self.backgroundColor = [UIColor clearColor];
		self.contentMode = UIViewContentModeScaleAspectFill;
		self.userInteractionEnabled = YES;
		UITapGestureRecognizer *tapGr = [[UITapGestureRecognizer alloc] initWithTarget:self
																				action:@selector(tapGrAction:)];
		[self addGestureRecognizer:tapGr];
	}
	return self;
}

- (void)setUrl:(NSString *)url {
	_url = url;
	[self qk_setImageUrl:[NSURL URLWithString:url] placeholder:[UIImage imageNamed:headUrl] size:self.frame.size cornerRadius:self.frame.size.width/2.0];
}

- (void)setUrlNotHaveCircle:(NSString *)urlNotHaveCircle {
	_url = urlNotHaveCircle;
	[self qk_setImageUrl:[NSURL URLWithString:urlNotHaveCircle] placeholder:[UIImage imageNamed:headUrl] size:self.frame.size cornerRadius:0.0];
}

- (void)setLocalImageName:(NSString *)localImageName {
	_localImageName = localImageName;
	self.image = [UIImage imageNamed:localImageName];
}

- (void)setLoacalImage:(UIImage *)loacalImage {
	_loacalImage = loacalImage;
	self.image = loacalImage;
}

- (void)setImageUrl:(NSString *)url isFit:(BOOL)fit isHaveDefault:(BOOL)isDefaultImage cornerRadius:(CGFloat)radius {
	_url = url;
	[self qk_setImageUrl:[NSURL URLWithString:url] placeholder:[UIImage imageNamed:isDefaultImage ? headUrl : @""] size:self.frame.size cornerRadius:radius isFit:fit];
}

- (void)setImageUrl:(NSString *)url withBordWidth:(CGFloat)bordWidth andBordColorSting:(NSString *)colorString {
	[self qk_setImageUrl:[NSURL URLWithString:url] placeholder:[UIImage imageNamed:headUrl] size:self.frame.size cornerRadius:self.frame.size.width/2.0 borderWidth:bordWidth borderColor:colorString];
}

- (void)setImageUrl:(NSURL *)url size:(CGSize)size cornerRadius:(CGFloat)radius {
	[self qk_setImageUrl:url placeholder:[UIImage imageNamed:headUrl] size:size cornerRadius:radius];
}
#pragma mark - Pri Property

- (void)tapGrAction:(UITapGestureRecognizer *)gr {
	if (self.delegate && [self.delegate respondsToSelector:@selector(clickImageView:)]) {
		[self.delegate clickImageView:self];
	}
}

@end
